﻿using System;
using System.Windows.Forms;
using DevExpress.XtraBars;
using NNS.UI;
using QLTB.BusinessObjects;

namespace QLTB.LinhKien.UI
{
    [System.ComponentModel.ToolboxItem(false)]
    public partial class ucLinhKienbyloai : MyUIBase
    {
        public ucLinhKienbyloai()
        {
            InitializeComponent();
        }

        public TBL_THIETBI ThietBi
        {
            set
            {
                CPUuc.ThietBi = value;
                Mainboarduc.ThietBi = value;
                Ramuc.ThietBi = value;
                Monitoruc.ThietBi = value;
                HDDuc.ThietBi = value;
                CD_DVDuc.ThietBi = value;
                Otheruc.ThietBi = value;
            }
        }

        private frmMain Controller
        {
            get { return (frmMain) ParentForm; }
        }

        public void Nap()
        {
            CPUuc.Nap();
            Mainboarduc.Nap();
            Ramuc.Nap();
            Monitoruc.Nap();
            HDDuc.Nap();
            CD_DVDuc.Nap();
            Otheruc.Nap();
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);
            //if (Controller!=null)
            //{
            //    Controller.iRefesh.ItemClick += new ItemClickEventHandler(iRefesh_ItemClick);
            //    Controller.IAdd.ItemClick += new ItemClickEventHandler(IAdd_ItemClick);
            //}
        }


        private void IAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            //throw new NotImplementedException();
            if (Visible)
            {
            }
        }

        private void iRefesh_ItemClick(object sender, ItemClickEventArgs e)
        {
            //throw new NotImplementedException();
            if (Visible)
            {
                //MessageBox.Show("Hi hi");  
            }
        }

        private void frmLinhKien_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = !Program._exit;
        }


        private void frmLinhKien_Activated(object sender, EventArgs e)
        {
            //frmMain f = (frmMain)ParentForm;
            //if (f != null)
            //{
            //    f.IgClose.Visible = true;
            //    f.iEdit.Visible = true;
            //    f.iUndo.Visibility = BarItemVisibility.Always;
            //    f.iCancel.Visibility = BarItemVisibility.Always;
            //    f.iGPrint.Visibility = BarItemVisibility.Always;
            //    f.iSave.Visibility = BarItemVisibility.Always;
            //    f.iClose.Visibility = BarItemVisibility.Always;
            //    f.iRefesh.Visibility = BarItemVisibility.Always;

            //}
        }

        private void frmLinhKien_Deactivate(object sender, EventArgs e)
        {
            //frmMain f = (frmMain)ParentForm;
            //if (f != null)
            //{
            //    f.IgClose.Visible = false;
            //    f.iEdit.Visible = false;
            //    f.iUndo.Visibility = BarItemVisibility.Never;
            //    f.iCancel.Visibility = BarItemVisibility.Never;
            //    f.iGPrint.Visibility = BarItemVisibility.Never;
            //    f.iSave.Visibility = BarItemVisibility.Never;
            //    f.iClose.Visibility = BarItemVisibility.Never;
            //    f.iRefesh.Visibility = BarItemVisibility.Never;
            //}
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            ParentForm.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Save();
        }

        protected void Save()
        {
            CPUuc.Save();
            Mainboarduc.Save();
            Ramuc.Save();
            Monitoruc.Save();
            HDDuc.Save();
            CD_DVDuc.Save();
            Otheruc.Save();
        }

        private void OnSaving(object sender, EventArgs e)
        {
            Save();
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                    //case Keys.Alt | Keys.D:
                    //    //MessageBox.Show("You are stupid");
                    //    return true;

                    //// some more cases...  

                    //case Keys.F1:
                    //    //ucToolBar_HelpClick(ucBar);
                    //    F11Execute();
                    //    return true;
                    //case Keys.F3:
                    //    F3Execute();
                    //    return true;
                    //case Keys.F4:
                    //    F4Execute();
                    //    return true;
                    //case Keys.F5:
                    //    F5Execute();
                    //    return true;
                    //case Keys.F6:
                    //    F9Execute();
                    //    return true;
                    //case Keys.F7:
                    //    F7Execute();
                    //    return true;
                    //case Keys.F8:
                    //    F8Execute();
                    //    return true;
                    //case Keys.F9:
                    //    F9Execute();
                    //    return true;
                    //case Keys.F11:
                    //    F11Execute();
                    //    return true;
                    //case Keys.F12:
                    //    F12Execute();
                    //    return true;

                case Keys.Escape:
                    ParentForm.Close();
                    EscapeExecute();
                    return true;

                case Keys.Alt | Keys.X:
                    ParentForm.Close();
                    return true;

                case Keys.F10:
                    F10Execute();
                    ParentForm.Close();
                    return true;
            }

            return false;
        }

        private void F10Execute()
        {
        }

        private void EscapeExecute()
        {
        }
    }
}